// 
// @Auther: by wujehy
// @Email:wujehy@qq.com
// @Data:2021/2/17.
// @Time:下午1:55.
// 
//

#include "Client.h"

bool Client::isClientStatus() const
{
    return m_client_status;
}

void Client::setClientStatus(bool status)
{
    m_client_status = status;
}

Client::~Client()
{
    threadPool.stop();
    // TODO 析构函数
    // 第三方日志系统与上层独立
    logger_debug("client 析构");
}

void Client::init_logger(void (*debug_loggerfunc)(const char *))
{
    this->debug_loggerfunc = debug_loggerfunc;
}

void Client::logger_debug(const char * msg_log)
{
    if (debug_loggerfunc != nullptr)
    {
        debug_loggerfunc(msg_log);
    }else
    {
        printf("测私日志: %s" , msg_log);
    }
}

void Client::setKey(const std::string &key, const std::string &value)
{

        m_key_value_cache[key] = value;

}

void Client::delKey(const std::string &key)
{
    auto findkey = m_key_value_cache.find(key);
    if (findkey != m_key_value_cache.end())
    {
        m_key_value_cache.erase(findkey->first);
    }
}

int Client::getKey(const std::string &key , std::string &get_value)
{
    auto findkey = m_key_value_cache.find(key);
    if (findkey != m_key_value_cache.end())
    {
        get_value = findkey->second;
        return EXIT_SUCCESS;
    } else{
        return EXIT_FAILURE;
    }
}

Client::Client() : threadPool(2)
{
    threadPool.start();
}
